package com.hospital.user.registration.controller;

import com.hospital.user.registration.service.UpdateServiceI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@Controller
public class UpdateController {

    @Autowired
    private UpdateServiceI updateServiceI;

    @RequestMapping("/update")
    public String reUp() {
        return "/Userr/registration/update";
    }

    @RequestMapping("/ReUpdate")
    public String reUpdate(int id, String idCard, String phone, String name, String pwd, HttpServletRequest req) {
        Map<String, Object> map = new HashMap();
        map.put("pwd", pwd);
        map.put("idCard", idCard);
        map.put("id", id);
        map.put("phone", phone);
        map.put("name", name);
        boolean b = updateServiceI.updatePwd(map);
        if (b) {
            req.setAttribute("result", "yes");
            return "/Userr/registration/update";
        }
        req.setAttribute("idCard", idCard);
        req.setAttribute("id", id);
        req.setAttribute("phone", phone);
        req.setAttribute("name", name);
        req.setAttribute("pwd", pwd);
        req.setAttribute("result", "no");
        return "/Userr/registration/update";
    }
}
